package com.ctrip.cap.client.jenkins;

import java.util.Arrays;
import java.util.List;

import com.ctrip.cap.client.impl.base.BaseClient;
import com.ctrip.cap.client.impl.base.BaseClientImpl.HttpMethodType;
import com.ctrip.cap.domain.LogRun;

public class JenkinsServiceClientImpl extends BaseClient{
	
	private final static String BASE_PATH = "/jenkins/service";
	private final static String PROGRESS = "/progress";
	private final static String FLUSH_PROGRESS = "/flush-progress";
	
	public JenkinsServiceClientImpl() {
		baseUrl = "http://mportal.dev.sh.ctripcorp.com:8080/benchmark";
	}
	
	public JenkinsServiceClientImpl(String jenkinsServer) {
		baseUrl = jenkinsServer;
	}
	
	public float getProgress(int runid) {
		return this.baseCall(BASE_PATH+PROGRESS, runid , HttpMethodType.GET, Float.class, "runid");		
	}
	
	public List<LogRun> flushProgress() {
		LogRun[] arrayLogRuns = this.baseCall(BASE_PATH+FLUSH_PROGRESS, null , HttpMethodType.GET, LogRun[].class);
		return Arrays.asList(arrayLogRuns);
	}
	
	public static void main(String[] args) {
		JenkinsServiceClientImpl jImpl = new JenkinsServiceClientImpl();
		System.out.println(jImpl.getProgress(10657));
		System.out.println(jImpl.flushProgress());
	}
}
